
var myexpress=require('./server/node_modules/express');
/*引入session和cookie模块*/
var session = require('./server/node_modules/express-session');
var cookie = require('./server/node_modules/cookie-parser');

/*手机验证*/
var myyz = require("./server/sms_send.js");
var yz = require("./server/yzm.js");

var myexe = require('./server/dao/execsql.js');
//var resgist = require('./server/dao/loginRegistDao.js');
var app=myexpress();

var DiscoveryHome=require("./server/dao/DiscoveryHome.js");
var List=require("./server/dao/List.js");
var thenewsDao=require("./server/dao/thenewsDao.js");
var mianDao=require("./server/dao/mianPagesDao.js");

//code 验证码全局
var code;

/*手机短信验证的配置信息*/
myyz.setConfig = {

    //appKey 登录后可以在 管理中心→账号信息 中进行查看
    appKey: '8b1a47fbecfd44abae5a94225314bcd2',

    //taken 登录后可以在 管理中心→应用管理 中进行查看
    token: '9wD20O61Ef8x',

    //templateId  这个就是你的短信签名了， 登录后可以在 管理中心→短信签名 中进行查看
    templateId: 'RSETSESEKESE'
};



app.set('port',8080);
/*设置开发者信息*/
app.configure(function(){
    /*配置session和cookie*/
    app.use(cookie());
    app.use(session({
        secret:'12345',
        name:'apptest',
        cookie:{maxAge:86400000}
    }));
   /*开发者日志*/
    app.use(myexpress.logger('dev'));
    app.use(myexpress.bodyParser());    //非get方法的转化
    app.use(myexpress.methodOverride());
    app.use(app.router);    //路由的分发
    app.use(myexpress.static(__dirname+'/client')); //配置资源的路径前面必须加上反斜线
    app.use(myexpress.errorHandler());  //设置错误的模块
});


app.listen(app.get('port'),function (){
    console.log('8080启动');
});

/*获取验证码*/
app.post("/pages/yanzheng.do", function (req, res) {
    var phone = req.body.phone;
    console.log("phone===="+phone);
    //var phone = "13198522975";
    //var phone = "13228163520";
    code = yz.createyzm();
    console.log("/yanzheng.code::" + code);
    myyz.sendSms(phone, code, function (err, data, mess) {
        if (err) {
            console.log(err);
        } else {
            console.log("data.body" + data.body);
            console.log("mess" + mess);
            console.log("JSON.parse(data.body).reason" + JSON.parse(data.body).reason);
            console.log("JSON.parse(mess).reason" + JSON.parse(mess).reason);
        }
    });
});

/*验证码验证*/
app.get("/pages/checkYzm.do", function (req, res) {
    var yzm = req.query.yzm;
    console.log("code:"+code);
    console.log("验证码:"+yzm);
    if(code!=yzm){
        res.send("error");
    }else{
        res.send("success");
    }
});


/*


app.post("/mainDetails.html", function (req,res) {
    console.log("in");
    console.log(res.query);
});

app.post("/mainDetails.html",mainpagesSql.demo1);*/
/*邓亮开始*/
app.get("/pages/myrandom.do",DiscoveryHome.randoms);
app.post("/pages/myctr.do",List.mylist);
app.post("/pages/dianzan.do",List.mydianzan);
/*邓亮结束*/

/*王培钰*/
//监听 注册 页面
app.post("/pages/insert.do",myexe.insert);
//app.post("/pages/registe.do", resgist.registSql);

//监听 登录 页面
app.post("/pages/shouji.do",myexe.shouji);
app.post("/pages/login.do",myexe.loginSql);
//进行拦截页面
app.get("/pages/mysession.do",myexe.mysession);
app.get("/pages/myInformation.do",myexe.myInf);
/*王培钰结束*/
/*郑工卜开始*/
app.get("/pages/thenews.do",thenewsDao.checknews);
app.get("/pages/thenews2.do",thenewsDao.checknews2);
app.post("/pages/Viewdetails.do",thenewsDao.Viewdetails);
app.post("/pages/Viewdetails2.do",thenewsDao.Viewdetails2);
/*郑工卜结束*/
/*伍峰林开始*/
app.get("/pages/mainlist.do",mianDao.mianlist);
//app.get("/pages/mainDetails.html",mianDao.mianthelist);
/*app.get("/pages/mainDetails.html", function (req, res) {
    console.log("123123123123");
    console.log(req.url);
    console.log(req.query);
    mianDao.mianthelist(req,res);

});*/

/*伍峰林结束*/
